// pages/my/mydetailed/mydetailed.js
import Dialog from '@vant/weapp/dialog/dialog';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        page: 0,
        list: []
    },
    //   获取数据
    getList() {
        wx.request({
            url: 'http://admin.bsmall.byesame.com/wx/order/list',
            data: {
                showType: this.data.active,
                page: this.data.page,
                limit: 10
            },
            header: {
                'x-byesame-token': wx.getStorageSync('token')
            },
            method: 'GET',
            success: (res) => {
                console.log("这是成功输出的", res);
                if (res.data.errno == 0) {
                    this.setData({
                        list: res.data.data.list
                    })
                    console.log("这里是List", this.data.list);
                }
            },
            fail: (err) => {
                console.log("这是错误", );
            }
        })
    },
    //切换标签页
    onChange(event) {
        //   console.log("这是标签页的数据",event);
        // wx.showToast({
        //   title: `切换到标签 ${event.detail.name}`,
        //   icon: 'none',
        // });
        this.setData({
            active: event.detail.index
        })
        this.getList()
    },
    //跳转支付页
    toPayment(e) {
        console.log("正在前往支付页面",e);
        wx.navigateTo({
            url: '../../payment/payment?orderId=' + e.currentTarget.dataset.orderid,
        })
    },
    //跳转订单详细页面
    toDetails(e) {
        console.log("正在前往订单详细页", e);
        wx.navigateTo({
            url: 'detailedOrder/detailedOrder?orderId=' + e.currentTarget.dataset.id,
        })
    },
    //取消订单
    toCancel(e) {
        // console.log("正在取消订单",e);
        Dialog.confirm({
                title: '确定要取消该订单吗？',
            })
            .then(() => {
                // on confirm
                wx.request({
                    url: 'http://admin.bsmall.byesame.com/wx/order/cancel',
                    data: {
                        orderId: e.currentTarget.dataset.orderid
                    },
                    method: "POST",
                    header: {
                        'x-byesame-token': wx.getStorageSync('token')
                    },
                    success: (res) => {
                        if (res.data.errno == 0) {
                            console.log("删除成功");
                            this.getList()
                        }
                    }

                })
            })
            .catch(() => {
                // on cancel
            });
    },
    //删除订单
    deleteOrder(e) {
        Dialog.confirm({
                title: '确定要删除该订单吗？',
            })
            .then(() => {
                // on confirm
                wx.request({
                    url: 'http://admin.bsmall.byesame.com/wx/order/delete',
                    data: {
                        orderId: e.currentTarget.dataset.orderid
                    },
                    method: "POST",
                    header: {
                        'x-byesame-token': wx.getStorageSync('token')
                    },
                    success: (res) => {
                        console.log(1111111);
                        if (res.data.errno == 0) {
                            console.log("删除成功");
                            this.getList()
                        }
                    }

                })
            })
            .catch(() => {
                // on cancel
            });

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const activeIndex = parseInt(decodeURIComponent(options.showtype || '0'), 10) || 0;
        console.log("这是新页面的", options);
        this.setData({
            active: activeIndex
        })
        this.getList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getList()

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})